package org.example.controller;

import io.seata.core.context.RootContext;
import org.example.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AccountController {

    @Autowired
    private AccountService accountService ;

    private static Logger logger = LoggerFactory.getLogger(AccountController.class) ;

    @GetMapping("/debit/{userId}/{money}")
    public ResponseEntity<Void> debit(@PathVariable("userId") String userId, @PathVariable("money") Integer money){
        logger.info("Account Service ... xid: " + RootContext.getXID());
        // 开始扣减余额
        accountService.debit(userId , money);
        return ResponseEntity.ok().build() ;
    }
}
